package com.android.activity;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * Splash
 * 
 * Lanza una serie de animaciones. Cuando termina va a DeviceActivity
 *
 */
public class SplashActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);
        startAnimating();
    }

    /**
     * Helper method to start the animation on the splash screen
     */
    private void startAnimating() {
       
        // Fade in image.
        ImageView logo = (ImageView) findViewById(R.id.img_logo_bluetooth);
        Animation fade2 = AnimationUtils.loadAnimation(this, R.anim.fade_in2);
        logo.startAnimation(fade2);
        // Fade in top title
        TextView titulo = (TextView) findViewById(R.id.TextViewTopTitle);
        Animation fade1 = AnimationUtils.loadAnimation(this, R.anim.fade_in);
        titulo.startAnimation(fade1);
        // Fade in autor name
        TextView autor1 = (TextView) findViewById(R.id.TextViewNameJavier);
        Animation fade3 = AnimationUtils.loadAnimation(this, R.anim.fade_in3);
        autor1.startAnimation(fade3);
     // Fade in autor name
        TextView autor4 = (TextView) findViewById(R.id.TextViewNameFrancisco);
        Animation fade4 = AnimationUtils.loadAnimation(this, R.anim.fade_in4);
        autor4.startAnimation(fade4);
     // Fade in autor name
        TextView autor5 = (TextView) findViewById(R.id.TextViewNameGuillermo);
        Animation fade5 = AnimationUtils.loadAnimation(this, R.anim.fade_in5);
        autor5.startAnimation(fade5);
     // Fade in autor name
        TextView autor6 = (TextView) findViewById(R.id.TextViewNameAlberto);
        Animation fade6 = AnimationUtils.loadAnimation(this, R.anim.fade_in6);
        autor6.startAnimation(fade6);
        // Transition to Main Menu when bottom title finishes animating
        fade6.setAnimationListener(new AnimationListener() {
            public void onAnimationEnd(Animation animation) {
                // Cuando la pantalla de bienvenida termina se accede a al busqueda de
            	//dispositivos bluetooth
                startActivity(new Intent(SplashActivity.this, DeviceActivity.class));
                SplashActivity.this.finish();
            }

            public void onAnimationRepeat(Animation animation) {
            }

            public void onAnimationStart(Animation animation) {
            }
        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        // Stop the animation
        TextView titulo = (TextView) findViewById(R.id.TextViewTopTitle);
        titulo.clearAnimation();
        
        ImageView logo = (ImageView) findViewById(R.id.img_logo_bluetooth);
        logo.clearAnimation();
        
        TextView autor1 = (TextView) findViewById(R.id.TextViewNameJavier);
        autor1.clearAnimation();
 
        TextView autor4 = (TextView) findViewById(R.id.TextViewNameFrancisco);
        autor4.clearAnimation();
  
        TextView autor5 = (TextView) findViewById(R.id.TextViewNameGuillermo);
        autor5.clearAnimation();
   
        TextView autor6 = (TextView) findViewById(R.id.TextViewNameAlberto);
        autor6.clearAnimation();

    }

    @Override
    protected void onResume() {
        super.onResume();

        // Start animating at the beginning so we get the full splash screen experience
        startAnimating();
    }
}
